﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace RI
{
    public partial class Frm_ShowUser : Form
    {
        private Business.UserList _user = new Business.UserList();

        public Frm_ShowUser(string cid)
        {
            InitializeComponent();
            BindItemCidUser(cid);
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            _user.username = "A";
            _user.password = "A";
            this.Close();
            this.Dispose();
        }

        private void BindItemCidUser(string cid)
        {
            using (Business bus = new Business())
            {
                dgvUserList.DataSource = bus.GetItemCatUser(cid);
            }
            if (dgvUserList.Rows.Count == 0)
            {
                MessageBox.Show("请先在该网站注册至少一个账户!", "提示",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information);
                btnOK.Enabled = false;
            }
        }

        public Business.UserList GetUser()
        {
            return _user;
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (dgvUserList.SelectedRows.Count != 0)
            {
                _user.username = dgvUserList.SelectedRows[0].Cells[2].Value.ToString();
                _user.password = dgvUserList.SelectedRows[0].Cells[3].Value.ToString();
                this.Close();
                this.Dispose();
            }
            else
            {
                MessageBox.Show("请选择一个账户!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void dgvUserList_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            if (dgvUserList.SelectedRows.Count != 0)
            {
                _user.username = dgvUserList.SelectedRows[0].Cells[2].Value.ToString();
                _user.password = dgvUserList.SelectedRows[0].Cells[3].Value.ToString();
                this.Close();
                this.Dispose();
            }
        }

        private void Frm_ShowUser_Load(object sender, EventArgs e)
        {
            if (dgvUserList.Rows.Count == 1)
            {
                SendKeys.Send("{ENTER}");
            }
        }
    }
}